////////////////////////////////////////////////////////////////////////////
//
//  Crytek Engine Source File.
//  Copyright (C), Crytek Studios, 2002.
// -------------------------------------------------------------------------
//  File name:   trackviewnodes.h
//  Version:     v1.00
//  Created:     29/4/2002 by Timur.
//  Compilers:   Visual Studio.NET
//  Description: TrackView's tree control.
// -------------------------------------------------------------------------
//  History:
//
////////////////////////////////////////////////////////////////////////////

#ifndef __TrackViewSequencesCtrl_h__
#define __TrackViewSequencesCtrl_h__

//#include "Controls\MltiTree.h"
#include "Controls\TreeCtrlReport.h"
#include <IMovieSystem.h>

#if _MSC_VER > 1000
#pragma once
#endif


// forward declarations.
struct IAnimNode;
struct IAnimTrack;
struct IAnimSequence;
struct IAnimSequenceGroup;

//////////////////////////////////////////////////////////////////////////
class CTrackViewSequencesCtrl : public CTreeCtrlReport
{
public:
	class CRecord : public CTreeItemRecord
	{
	public:
		CRecord(IAnimSequence *pSequence) : m_pSequence(pSequence), m_pGroup(NULL), 
																				CTreeItemRecord() 
		{
			string name = pSequence->GetName();
			m_name = name.c_str();
			m_bIsGroup = false;
			Init();
		}
		CRecord(IAnimSequenceGroup *pGroup) : m_pSequence(NULL), m_pGroup(pGroup),
																					CTreeItemRecord()
		{
			string name = pGroup->GetName();
			m_name = name.c_str();
			m_bIsGroup = true;
			Init();
		}

		IAnimSequence* GetSequence() const
		{ return m_pSequence; }
		IAnimSequenceGroup* GetSequenceGroup() const
		{ return m_pGroup; }

	private:
		_smart_ptr<IAnimSequence> m_pSequence;
		_smart_ptr<IAnimSequenceGroup> m_pGroup;

		void Init()
		{
			CXTPReportRecordItem *pItem = new CXTPReportRecordItemText(m_name);
			AddItem(pItem);
			const int filmIconIndex = 11;
			const int folderIconIndex = 1;
			if (m_bIsGroup)
			{
				pItem->SetBold(TRUE);
				pItem->SetIconIndex(folderIconIndex);
			}
			else
				pItem->SetIconIndex(filmIconIndex);
		}
	};

public:
	CTrackViewSequencesCtrl();
	void SetTrackViewDialog( class CTrackViewDialog* pDlg ) { m_pTrackViewDialog = pDlg; }

	//////////////////////////////////////////////////////////////////////////
	// Callbacks.
	//////////////////////////////////////////////////////////////////////////
	virtual void OnFillItems();
	virtual void OnSelectionChanged();
	virtual void OnDragAndDrop( CXTPReportRow *pRow, CPoint absoluteCursorPos );
	//////////////////////////////////////////////////////////////////////////

	void SetCurrentSequence( IAnimSequence *curr );
protected:
	DECLARE_MESSAGE_MAP()
	afx_msg void OnLButtonDown( UINT nFlags, CPoint point );
	afx_msg void OnNMRclick(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnValueChanged(NMHDR*  pNotifyStruct, LRESULT* result);

	static void RecursiveFill(CXTPReportRecords *pRecords, IAnimSequenceGroup *pGroup);
	static bool IsLocked(const IAnimSequence *pAnimSequence);
	static bool IsLocked(const IAnimSequenceGroup *pGroup);
	static void SetPopupMenuLock(CMenu* menu);

	static void ToggleAutoStart(IAnimSequence *pSequence);
	static void ToggleSequenceFlag(IAnimSequence *pSequence, int flag);
protected:
	class CTrackViewDialog *m_pTrackViewDialog;
	bool m_bSelectionChangedHere;
};

#endif // __TrackViewSequences_h__